package com.dsh.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {

    public static HttpServletRequest getRequest() {
        ServletRequestAttributes requestAttributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        if (requestAttributes != null) {
            return requestAttributes.getRequest();
        }

        return null;
    }

    /**
     * 获取来自ZUUL传递的userId
     * @return
     */
    public static String userId() {
        try {
            String userId = getRequest().getHeader("userId");
            return userId;
        } catch (Exception ex) {
            return null;

        }
    }

}